﻿<Window x:Class="MouseExtender.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:uc="clr-namespace:MouseExtender.Controls.UserControls"
                xmlns:t="clr-namespace:Hardcodet.Wpf.TaskbarNotification"
                xmlns:common="clr-namespace:MouseExtender.Logic.Common"
                xmlns:managers="clr-namespace:MouseExtender.Logic.Managers"
                xmlns:resx="clr-namespace:MouseExtender.Resources"
                xmlns:converters="clr-namespace:MouseExtender.Logic.Converters"
                Title="Mouse Extender" ShowInTaskbar="False" WindowStyle="None" ResizeMode="NoResize" SizeToContent="WidthAndHeight" Background="{x:Null}"
                AllowsTransparency="True" Initialized="Window_Initialized" Loaded="Window_Loaded" Activated="Window_Activated"
                Deactivated="Window_Deactivated" LayoutUpdated="Window_LayoutUpdated" ContentRendered="Window_ContentRendered" Unloaded="Window_Unloaded" Cursor="AppStarting" MouseRightButtonUp="Window_MouseRightButtonUp">
    <Window.Resources>
        <converters:CurrentCultureConverter x:Key="CultureConverter"/>
        <Style x:Key="MinimizeButtonStyle" TargetType="Button">
            <EventSetter Event="Click" Handler="Window_Minimize"/>
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ControlTemplate.Triggers>
                            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                <BeginStoryboard Storyboard="{StaticResource EnterBlueGlowStorybaord}"/>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                <BeginStoryboard Storyboard="{StaticResource LeaveBlueGlowStorybaord}"/>
                            </EventTrigger>
                        </ControlTemplate.Triggers>
                        <Canvas Height="9" Width="9" Margin="5,-2,5,0">
                            <Canvas.BitmapEffect>
                                <BitmapEffectGroup>
                                    <BitmapEffectGroup.Children>
                                        <BitmapEffectCollection>
                                            <OuterGlowBitmapEffect x:Name="effect1" GlowColor="#009BDEFA" GlowSize="2"/>
                                            <OuterGlowBitmapEffect x:Name="effect2" GlowColor="#009BDEFA" GlowSize="3"/>
                                            <OuterGlowBitmapEffect x:Name="effect3" GlowColor="#00007BAE" GlowSize="5"/>
                                            <OuterGlowBitmapEffect x:Name="effect4" GlowColor="#00007BAE" GlowSize="8"/>
                                            <OuterGlowBitmapEffect x:Name="effect5" GlowColor="#00004B6A" GlowSize="14"/>
                                        </BitmapEffectCollection>
                                    </BitmapEffectGroup.Children>
                                </BitmapEffectGroup>
                            </Canvas.BitmapEffect>
                            <Canvas.Background>
                                <DrawingBrush Stretch="Uniform" AlignmentY="Bottom">
                                    <DrawingBrush.Drawing>
                                        <GeometryDrawing>
                                            <GeometryDrawing.Pen>
                                                <Pen Brush="#FF333333" Thickness="2"/>
                                            </GeometryDrawing.Pen>
                                            <GeometryDrawing.Geometry>
                                                <LineGeometry StartPoint="0,7" EndPoint="8,7"/>
                                            </GeometryDrawing.Geometry>
                                        </GeometryDrawing>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Canvas.Background>
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="CloseButtonStyle" TargetType="Button">
            <EventSetter Event="Click" Handler="Exit"/>
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ControlTemplate.Triggers>
                            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                <BeginStoryboard Storyboard="{StaticResource EnterRedGlowStoryboard}"/>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                <BeginStoryboard Storyboard="{StaticResource LeaveRedGlowStoryboard}"/>
                            </EventTrigger>
                        </ControlTemplate.Triggers>
                        <Canvas Height="9" Width="9" Margin="5,1,9,0">
                            <Canvas.BitmapEffect>
                                <BitmapEffectGroup>
                                    <BitmapEffectGroup.Children>
                                        <BitmapEffectCollection>
                                            <OuterGlowBitmapEffect x:Name="effect1" GlowColor="#00BF5E42" GlowSize="2"/>
                                            <OuterGlowBitmapEffect x:Name="effect2" GlowColor="#00BF5E42" GlowSize="3"/>
                                            <OuterGlowBitmapEffect x:Name="effect3" GlowColor="#008B2A10" GlowSize="5"/>
                                            <OuterGlowBitmapEffect x:Name="effect4" GlowColor="#008B2A10" GlowSize="8"/>
                                            <OuterGlowBitmapEffect x:Name="effect5" GlowColor="#00A02605" GlowSize="14"/>
                                        </BitmapEffectCollection>
                                    </BitmapEffectGroup.Children>
                                </BitmapEffectGroup>
                            </Canvas.BitmapEffect>
                            <Canvas.Background>
                                <DrawingBrush Stretch="Uniform">
                                    <DrawingBrush.Drawing>
                                        <GeometryDrawing>
                                            <GeometryDrawing.Pen>
                                                <Pen Brush="#FF333333" Thickness="2"/>
                                            </GeometryDrawing.Pen>
                                            <GeometryDrawing.Geometry>
                                                <PathGeometry Figures="M0,5 L8,13 M8,5 L0,13"/>
                                            </GeometryDrawing.Geometry>
                                        </GeometryDrawing>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Canvas.Background>
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="PinButtonStyle" TargetType="ToggleButton">
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <ControlTemplate.Triggers>
                            <EventTrigger RoutedEvent="ToggleButton.Checked">
                                <BeginStoryboard>
                                    <Storyboard Timeline.DesiredFrameRate="{StaticResource ResourceKey=animationFrameRate}">
                                        <DoubleAnimation Storyboard.TargetName="pinRotate" Storyboard.TargetProperty="Angle" To="-45" Duration="0:0:0.3"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="ToggleButton.Unchecked">
                                <BeginStoryboard>
                                    <Storyboard Timeline.DesiredFrameRate="{StaticResource ResourceKey=animationFrameRate}">
                                        <DoubleAnimation Storyboard.TargetName="pinRotate" Storyboard.TargetProperty="Angle" To="0" Duration="0:0:0.3"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                <BeginStoryboard Storyboard="{StaticResource EnterBlueGlowStorybaord}"/>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                <BeginStoryboard Storyboard="{StaticResource LeaveBlueGlowStorybaord}"/>
                            </EventTrigger>
                        </ControlTemplate.Triggers>
                        <Canvas Height="15" Width="15" Margin="0,1,5,0">
                            <Canvas.RenderTransform>
                                <RotateTransform x:Name="pinRotate" Angle="0" CenterX="7.5" CenterY="10"/>
                            </Canvas.RenderTransform>
                            <Canvas.BitmapEffect>
                                <BitmapEffectGroup>
                                    <BitmapEffectGroup.Children>
                                        <BitmapEffectCollection>
                                            <OuterGlowBitmapEffect x:Name="effect1" GlowColor="#009BDEFA" GlowSize="2"/>
                                            <OuterGlowBitmapEffect x:Name="effect2" GlowColor="#009BDEFA" GlowSize="3"/>
                                            <OuterGlowBitmapEffect x:Name="effect3" GlowColor="#00007BAE" GlowSize="5"/>
                                            <OuterGlowBitmapEffect x:Name="effect4" GlowColor="#00007BAE" GlowSize="8"/>
                                            <OuterGlowBitmapEffect x:Name="effect5" GlowColor="#00004B6A" GlowSize="14"/>
                                        </BitmapEffectCollection>
                                    </BitmapEffectGroup.Children>
                                </BitmapEffectGroup>
                            </Canvas.BitmapEffect>
                            <Canvas.Background>
                                <DrawingBrush Stretch="Uniform">
                                    <DrawingBrush.Drawing>
                                        <GeometryDrawing Brush="#FF333333">
                                            <GeometryDrawing.Geometry>
                                                <PathGeometry Figures="M 37.0787,158.871C 37.0787,158.871 36.9464,159.4 36.2587,159.4C 35.5709,159.4 34.8303,159.231 34.5393,157.749C 34.5342,157.723 32,157.31 32,157.31L 34.5393,156.924C 34.5393,156.924 34.7243,155.3 36.1727,155.3C 36.6819,155.3 36.9729,156.067 36.9729,156.067L 38.1797,156.391C 38.1797,156.391 38.7748,155.618 39.4097,155.618C 40.0445,155.618 40.3884,156.517 40.3884,157.297C 40.3884,158.078 40.1437,159.083 39.5089,159.083C 38.874,159.083 38.2392,158.402 38.1664,158.236C 38.1309,158.155 37.0786,158.868 37.0786,158.868"/>
                                            </GeometryDrawing.Geometry>
                                        </GeometryDrawing>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Canvas.Background>
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Window.InputBindings>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D1"  CommandParameter="0"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D2"  CommandParameter="1"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D3"  CommandParameter="2"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D4"  CommandParameter="3"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D5"  CommandParameter="4"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D6"  CommandParameter="5"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D7"  CommandParameter="6"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D8"  CommandParameter="7"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D9"  CommandParameter="8"/>
        <KeyBinding Command="common:Commands.ChangeTab" Gesture="Alt+D0"  CommandParameter="9"/>
        <KeyBinding Command="common:Commands.About" Gesture="F1" />
    </Window.InputBindings>
    <Window.CommandBindings>
        <CommandBinding Command="common:Commands.About" Executed="About_Executed"/>
        <CommandBinding Command="common:Commands.AddFile" Executed="AddFile_Executed"/>
        <CommandBinding Command="common:Commands.AddFolder" Executed="AddFolder_Executed"/>
        <CommandBinding Command="common:Commands.AddRunningProgram" Executed="AddRunningProgram_Executed"/>
        <CommandBinding Command="common:Commands.AddTab" Executed="AddTab_Executed" CanExecute="AddTab_CanExecute"/>
        <CommandBinding Command="common:Commands.AddUrl" Executed="AddUrl_Executed"/>
        <CommandBinding Command="common:Commands.ApplySettings" Executed="ApplySettings_Executed"/>
        <CommandBinding Command="common:Commands.CancelPopup" Executed="CancelPopup_Executed"/>
        <CommandBinding Command="common:Commands.CheckUpdates" Executed="CheckUpdates_Executed"/>
        <CommandBinding Command="common:Commands.Delete" Executed="Delete_Executed"/>
        <CommandBinding Command="common:Commands.Disable" Executed="Disable_Executed"/>
        <CommandBinding Command="common:Commands.DontHidePanel" Executed="DontHidePanel_Executed"/>
        <CommandBinding Command="common:Commands.EditItem" Executed="EditItem_Executed"/>
        <CommandBinding Command="common:Commands.EditTab" Executed="EditTab_Executed"/>
        <CommandBinding Command="common:Commands.Exit" Executed="Exit_Executed"/>
        <CommandBinding Command="common:Commands.RemoveTab" Executed="RemoveTab_Executed"/>
        <CommandBinding Command="common:Commands.SaveItemSettings" Executed="SaveItemSettings_Executed"/>
        <CommandBinding Command="common:Commands.SaveTabSettings" Executed="SaveTabSettings_Executed"/>
        <CommandBinding Command="common:Commands.SaveUrl" Executed="SaveUrl_Executed"/>
        <CommandBinding Command="common:Commands.SendToAnotherTab" Executed="SendToAnotherTab_Executed"/>
        <CommandBinding Command="common:Commands.ShowSettings" Executed="ShowSettings_Executed"/>
        <CommandBinding Command="common:Commands.ChangeTab" Executed="ChangeTab_Executed"/>
    </Window.CommandBindings>
    <Window.ContextMenu>
        <ContextMenu>
            <MenuItem Command="common:Commands.AddFile"/>
            <MenuItem Command="common:Commands.AddFolder"/>
            <MenuItem Command="common:Commands.AddUrl"/>
            <MenuItem Command="common:Commands.AddRunningProgram"/>
            <MenuItem Command="common:Commands.AddTab"/>
            <Separator/>
            <MenuItem Command="common:Commands.Disable" x:Name="miDisable"/>
            <MenuItem Command="common:Commands.ShowSettings"/>
            <MenuItem Command="common:Commands.CheckUpdates"/>
            <MenuItem Command="common:Commands.About"/>
            <MenuItem Command="common:Commands.Exit"/>
        </ContextMenu>
    </Window.ContextMenu>
    <Grid x:Name="grid" AllowDrop="True" Drop="DragDrop" Margin="15,15,25,25" MouseLeftButtonDown="Grid_MouseLeftButtonDown">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.BitmapEffect>
            <DropShadowBitmapEffect Direction="315" Opacity="0.8" ShadowDepth="5" Softness="0.3"/>
        </Grid.BitmapEffect>
        <Border x:Name="windowBackground" CornerRadius="8,0,8,8" Grid.RowSpan="3" Grid.ColumnSpan="4" Opacity="0.7">
            <!--<Border.Effect>
                <BlurEffect Radius="1" />
            </Border.Effect>-->
            <Border.Background>
                <ImageBrush ImageSource="/MouseExtender;component/Images/Background.png" Stretch="Fill" TileMode="FlipXY" ViewportUnits="Absolute" Viewport="0,0 100,100"/>
            </Border.Background>
        </Border>
        <Border CornerRadius="0,0,8,0" Width="100" Grid.ColumnSpan="4" Grid.RowSpan="3" HorizontalAlignment="Right">
            <Border.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                    <GradientStop Color="#007A7A7A" Offset="0"/>
                    <GradientStop Color="#4E202020" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
        </Border>
        <Border CornerRadius="8,0,0,0" Height="100" Grid.ColumnSpan="4" Grid.RowSpan="3" VerticalAlignment="Top">
            <Border.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Color="#4E202020" Offset="0"/>
                    <GradientStop Color="#007A7A7A" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
        </Border>
        <uc:TabsUC x:Name="ucTabs" Grid.Column="0" Grid.Row="0" TabChanged="ucTabs_TabChanged"/>
        <ToggleButton x:Name="tbtnPin" Grid.Column="1" Grid.Row="0" Style="{StaticResource PinButtonStyle}" Command="common:Commands.DontHidePanel"/>
        <Button x:Name="btnMinimize" Grid.Column="2" Grid.Row="0" Style="{StaticResource MinimizeButtonStyle}"/>
        <Button x:Name="btnClose" Grid.Column="3" Grid.Row="0" Style="{StaticResource CloseButtonStyle}"/>
        <uc:SystemButtonsBarUC x:Name="ucSystemButtonsBar" Grid.Row="1" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" VerticalAlignment="Top"/>
        <uc:LauncherUC x:Name="ucLauncher" Grid.Row="2" Grid.ColumnSpan="4" HorizontalAlignment="Left" VerticalAlignment="Top" SizeChanged="ucLauncher_SizeChanged"/>
        <TextBlock x:Name="firstTimeNote" Text="{x:Static resx:UIResources.MainWindow_FirstRun}" Grid.Row="2" Grid.ColumnSpan="4" TextWrapping="Wrap" Width="{Binding ElementName=ucLauncher, Path=ActualWidth}" Padding="10" FontSize="11" FontWeight="Bold" Foreground="#FF333333" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed" TextAlignment="Center">
        </TextBlock>
        <t:TaskbarIcon x:Name="tbIcon" ToolTipText="Mouse Extender" TrayLeftMouseDown="tbIcon_TrayLeftMouseDown" IconSource="/Icons/mouse-extender.ico">
            <t:TaskbarIcon.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{x:Static resx:UIResources.Menu_ShowPanel}" Click="MenuItem_ShowClick"/>
                    <MenuItem x:Name="miDisableTray" Click="MenuItem_DisableClick"/>
                    <MenuItem Header="{x:Static resx:UIResources.Menu_CheckForUpdates}" Click="CheckUpdates_Executed"/>
                    <MenuItem Header ="{x:Static resx:UIResources.Menu_Settings}" Click="MenuItem_ShowSettings"/>
                    <MenuItem Header="{x:Static resx:UIResources.Menu_About}" Click="MenuItem_AboutClick"/>
                    <MenuItem x:Name="setLanguage" Header="{x:Static resx:UIResources.Command_SetLanguage}" ItemsSource="{x:Static managers:ResourceManager.AvailableCultures}">
                        <MenuItem.ItemTemplate>
                            <DataTemplate>
                                <MenuItem IsCheckable="True" 
                                    IsChecked="{Binding Path=., Converter={StaticResource CultureConverter}, ConverterParameter=True}"
                                    IsEnabled="{Binding Path=., Converter={StaticResource CultureConverter}, ConverterParameter=False}" 
                                    Header="{Binding Path=., Converter={StaticResource CultureConverter}}"
                                    Click="SetLanguage_Click" 
                                    CommandParameter="{Binding}">
                                </MenuItem>
                            </DataTemplate>
                        </MenuItem.ItemTemplate>
                    </MenuItem>
                    <MenuItem Header="{x:Static resx:UIResources.Menu_Exit}" Click="MenuItem_ExitClick"/>
                </ContextMenu>
            </t:TaskbarIcon.ContextMenu>
        </t:TaskbarIcon>
    </Grid>
</Window>
